package com.amkai.aes.webservice.binary.objecthandler;

import java.io.Serializable;

import com.amkai.aes.aescommon.service.binary.job.OccupationTransferJob;
import com.amkai.aes.generatedbeans.registration.items.Occupation;
import com.amkai.aes.webservice.binary.JobObjectHandler;
import com.amkai.common.extensions.hibernate.config.SiteManager;
import com.amkai.common.extensions.hibernate.config.manager.SessionManager;
import com.amkai.rad.designerbase.handlers.TransferMode;

public class OccupationHandler implements JobObjectHandler<OccupationTransferJob, Occupation, Occupation> {
	/** 
	 * Overriden method
	 * @param job
	 * @param object
	 * @return
	 * @throws Exception
	 * @see com.amkai.aes.webservice.binary.JobObjectHandler#process(E, InputObject)
	 * 
	 */
	public Occupation process(OccupationTransferJob job, Occupation object) throws Exception {
		
		SessionManager sm = SiteManager.Start();
		
		TransferMode mode = TransferMode.values()[job.getTransferMode()];
		
		switch(mode) {
		case LOAD: {
			object = sm.load(Occupation.class, job.getId());
			break;
		}
		case SAVE_OR_UPDATE: {
			if (object.getId() != null) {
				sm.saveOrUpdate(object);
				break;
			}
			//if don't have an id, continue with SAVE 
		}
		case SAVE: {
			Serializable id = sm.save(object);
			object.setId((Long)id);
			break;
		}
		case DELETE: {
			sm.delete(object);
			break;
		}
		default: {
			object = null;
			break;
		}
		}
		
		return object;
	}
}
